import { SendPlans } from './sendPlan';
let _SendPlans = SendPlans;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import SendPlanMock from './mdp/arc/send/sendPlanMock';
 * SendPlanMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mdp/arc/send/sendPlan/listKey').reply(config => {
      let params = config.params;
      let mockSendPlans = _SendPlans.filter(sendPlan => {
      	if(params.id||params.id==''){ if( sendPlan.id.indexOf(params.id)>=0) return true;}
      	if(params.isSendOa||params.isSendOa==''){ if( sendPlan.isSendOa.indexOf(params.isSendOa)>=0) return true;}
      	if(params.isSendWxpub||params.isSendWxpub==''){ if( sendPlan.isSendWxpub.indexOf(params.isSendWxpub)>=0) return true;}
      	if(params.isSendShortMsg||params.isSendShortMsg==''){ if( sendPlan.isSendShortMsg.indexOf(params.isSendShortMsg)>=0) return true;}
      	if(params.needReply||params.needReply==''){ if( sendPlan.needReply.indexOf(params.needReply)>=0) return true;}
      	if(params.isSendDept||params.isSendDept==''){ if( sendPlan.isSendDept.indexOf(params.isSendDept)>=0) return true;}
      	if(params.isSendUser||params.isSendUser==''){ if( sendPlan.isSendUser.indexOf(params.isSendUser)>=0) return true;}
      	if(params.planSendDate||params.planSendDate==''){ if( sendPlan.planSendDate.indexOf(params.planSendDate)>=0) return true;}
      	if(params.isSendEmail||params.isSendEmail==''){ if( sendPlan.isSendEmail.indexOf(params.isSendEmail)>=0) return true;}
      	if(params.encryptType||params.encryptType==''){ if( sendPlan.encryptType.indexOf(params.encryptType)>=0) return true;}
      	if(params.sendStartDate||params.sendStartDate==''){ if( sendPlan.sendStartDate.indexOf(params.sendStartDate)>=0) return true;}
      	if(params.remark||params.remark==''){ if( sendPlan.remark.indexOf(params.remark)>=0) return true;}
      	if(params.sendRemark||params.sendRemark==''){ if( sendPlan.sendRemark.indexOf(params.sendRemark)>=0) return true;}
      	if(params.isForceEnd||params.isForceEnd==''){ if( sendPlan.isForceEnd.indexOf(params.isForceEnd)>=0) return true;}
      	if(params.isSendEnd||params.isSendEnd==''){ if( sendPlan.isSendEnd.indexOf(params.isSendEnd)>=0) return true;}
      	if(params.isIncludeSubDept||params.isIncludeSubDept==''){ if( sendPlan.isIncludeSubDept.indexOf(params.isIncludeSubDept)>=0) return true;}
      	if(params.createUserid||params.createUserid==''){ if( sendPlan.createUserid.indexOf(params.createUserid)>=0) return true;}
      	if(params.createDeptid||params.createDeptid==''){ if( sendPlan.createDeptid.indexOf(params.createDeptid)>=0) return true;}
      	if(params.createDate||params.createDate==''){ if( sendPlan.createDate.indexOf(params.createDate)>=0) return true;}
      	if(params.canRead||params.canRead==''){ if( sendPlan.canRead.indexOf(params.canRead)>=0) return true;}
      	if(params.canShare||params.canShare==''){ if( sendPlan.canShare.indexOf(params.canShare)>=0) return true;}
      	if(params.canEdit||params.canEdit==''){ if( sendPlan.canEdit.indexOf(params.canEdit)>=0) return true;}
      	if(params.canDel||params.canDel==''){ if( sendPlan.canDel.indexOf(params.canDel)>=0) return true;}
      	if(params.isExternalClient||params.isExternalClient==''){ if( sendPlan.isExternalClient.indexOf(params.isExternalClient)>=0) return true;}
      	if(params.isFromArchive||params.isFromArchive==''){ if( sendPlan.isFromArchive.indexOf(params.isFromArchive)>=0) return true;}
      	if(params.archiveId||params.archiveId==''){ if( sendPlan.archiveId.indexOf(params.archiveId)>=0) return true;}
      	if(params.isSendQyh||params.isSendQyh==''){ if( sendPlan.isSendQyh.indexOf(params.isSendQyh)>=0) return true;}
      	if(params.isSendOo||params.isSendOo==''){ if( sendPlan.isSendOo.indexOf(params.isSendOo)>=0) return true;}
      	if(params.isSendOt||params.isSendOt==''){ if( sendPlan.isSendOt.indexOf(params.isSendOt)>=0) return true;}
      	if(params.sendStatus||params.sendStatus==''){ if( sendPlan.sendStatus.indexOf(params.sendStatus)>=0) return true;}
      	if(params.planEndDate||params.planEndDate==''){ if( sendPlan.planEndDate.indexOf(params.planEndDate)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockSendPlans
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mdp/arc/send/sendPlan/list').reply(config => {
      let params = config.params;
      let mockSendPlans = _SendPlans.filter(sendPlan => {
      	var isTrue=false;
      	if(params.id||params.id==''){if(sendPlan.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendOa||params.isSendOa==''){if(sendPlan.isSendOa.indexOf(params.isSendOa)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendWxpub||params.isSendWxpub==''){if(sendPlan.isSendWxpub.indexOf(params.isSendWxpub)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendShortMsg||params.isSendShortMsg==''){if(sendPlan.isSendShortMsg.indexOf(params.isSendShortMsg)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.needReply||params.needReply==''){if(sendPlan.needReply.indexOf(params.needReply)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendDept||params.isSendDept==''){if(sendPlan.isSendDept.indexOf(params.isSendDept)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendUser||params.isSendUser==''){if(sendPlan.isSendUser.indexOf(params.isSendUser)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.planSendDate||params.planSendDate==''){if(sendPlan.planSendDate.indexOf(params.planSendDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendEmail||params.isSendEmail==''){if(sendPlan.isSendEmail.indexOf(params.isSendEmail)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.encryptType||params.encryptType==''){if(sendPlan.encryptType.indexOf(params.encryptType)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.sendStartDate||params.sendStartDate==''){if(sendPlan.sendStartDate.indexOf(params.sendStartDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.remark||params.remark==''){if(sendPlan.remark.indexOf(params.remark)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.sendRemark||params.sendRemark==''){if(sendPlan.sendRemark.indexOf(params.sendRemark)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isForceEnd||params.isForceEnd==''){if(sendPlan.isForceEnd.indexOf(params.isForceEnd)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendEnd||params.isSendEnd==''){if(sendPlan.isSendEnd.indexOf(params.isSendEnd)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isIncludeSubDept||params.isIncludeSubDept==''){if(sendPlan.isIncludeSubDept.indexOf(params.isIncludeSubDept)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.createUserid||params.createUserid==''){if(sendPlan.createUserid.indexOf(params.createUserid)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.createDeptid||params.createDeptid==''){if(sendPlan.createDeptid.indexOf(params.createDeptid)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.createDate||params.createDate==''){if(sendPlan.createDate.indexOf(params.createDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.canRead||params.canRead==''){if(sendPlan.canRead.indexOf(params.canRead)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.canShare||params.canShare==''){if(sendPlan.canShare.indexOf(params.canShare)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.canEdit||params.canEdit==''){if(sendPlan.canEdit.indexOf(params.canEdit)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.canDel||params.canDel==''){if(sendPlan.canDel.indexOf(params.canDel)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isExternalClient||params.isExternalClient==''){if(sendPlan.isExternalClient.indexOf(params.isExternalClient)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isFromArchive||params.isFromArchive==''){if(sendPlan.isFromArchive.indexOf(params.isFromArchive)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.archiveId||params.archiveId==''){if(sendPlan.archiveId.indexOf(params.archiveId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendQyh||params.isSendQyh==''){if(sendPlan.isSendQyh.indexOf(params.isSendQyh)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendOo||params.isSendOo==''){if(sendPlan.isSendOo.indexOf(params.isSendOo)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendOt||params.isSendOt==''){if(sendPlan.isSendOt.indexOf(params.isSendOt)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.sendStatus||params.sendStatus==''){if(sendPlan.sendStatus.indexOf(params.sendStatus)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.planEndDate||params.planEndDate==''){if(sendPlan.planEndDate.indexOf(params.planEndDate)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockSendPlans
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockSendPlans.length;
      mockSendPlans = mockSendPlans.filter((sendPlan, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockSendPlans,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mdp/arc/send/sendPlan/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _SendPlans = _SendPlans.filter(sendPlan => sendPlan.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mdp/arc/send/sendPlan/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _SendPlans = _SendPlans.filter(sendPlan => !params.includes(sendPlan.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mdp/arc/send/sendPlan/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { id,isSendOa,isSendWxpub,isSendShortMsg,needReply,isSendDept,isSendUser,planSendDate,isSendEmail,encryptType,sendStartDate,remark,sendRemark,isForceEnd,isSendEnd,isIncludeSubDept,createUserid,createDeptid,createDate,canRead,canShare,canEdit,canDel,isExternalClient,isFromArchive,archiveId,isSendQyh,isSendOo,isSendOt,sendStatus,planEndDate } = params;
      _SendPlans.some(sendPlan => {
        if (sendPlan.id === id) {
			sendPlan.id = id;
			sendPlan.isSendOa = isSendOa;
			sendPlan.isSendWxpub = isSendWxpub;
			sendPlan.isSendShortMsg = isSendShortMsg;
			sendPlan.needReply = needReply;
			sendPlan.isSendDept = isSendDept;
			sendPlan.isSendUser = isSendUser;
			sendPlan.planSendDate = planSendDate;
			sendPlan.isSendEmail = isSendEmail;
			sendPlan.encryptType = encryptType;
			sendPlan.sendStartDate = sendStartDate;
			sendPlan.remark = remark;
			sendPlan.sendRemark = sendRemark;
			sendPlan.isForceEnd = isForceEnd;
			sendPlan.isSendEnd = isSendEnd;
			sendPlan.isIncludeSubDept = isIncludeSubDept;
			sendPlan.createUserid = createUserid;
			sendPlan.createDeptid = createDeptid;
			sendPlan.createDate = createDate;
			sendPlan.canRead = canRead;
			sendPlan.canShare = canShare;
			sendPlan.canEdit = canEdit;
			sendPlan.canDel = canDel;
			sendPlan.isExternalClient = isExternalClient;
			sendPlan.isFromArchive = isFromArchive;
			sendPlan.archiveId = archiveId;
			sendPlan.isSendQyh = isSendQyh;
			sendPlan.isSendOo = isSendOo;
			sendPlan.isSendOt = isSendOt;
			sendPlan.sendStatus = sendStatus;
			sendPlan.planEndDate = planEndDate
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mdp/arc/send/sendPlan/add').reply(config => {
      var params = JSON.parse( config.data );
      let { id,isSendOa,isSendWxpub,isSendShortMsg,needReply,isSendDept,isSendUser,planSendDate,isSendEmail,encryptType,sendStartDate,remark,sendRemark,isForceEnd,isSendEnd,isIncludeSubDept,createUserid,createDeptid,createDate,canRead,canShare,canEdit,canDel,isExternalClient,isFromArchive,archiveId,isSendQyh,isSendOo,isSendOt,sendStatus,planEndDate } = params;
      _SendPlans.push({
		id:id,
		isSendOa:isSendOa,
		isSendWxpub:isSendWxpub,
		isSendShortMsg:isSendShortMsg,
		needReply:needReply,
		isSendDept:isSendDept,
		isSendUser:isSendUser,
		planSendDate:planSendDate,
		isSendEmail:isSendEmail,
		encryptType:encryptType,
		sendStartDate:sendStartDate,
		remark:remark,
		sendRemark:sendRemark,
		isForceEnd:isForceEnd,
		isSendEnd:isSendEnd,
		isIncludeSubDept:isIncludeSubDept,
		createUserid:createUserid,
		createDeptid:createDeptid,
		createDate:createDate,
		canRead:canRead,
		canShare:canShare,
		canEdit:canEdit,
		canDel:canDel,
		isExternalClient:isExternalClient,
		isFromArchive:isFromArchive,
		archiveId:archiveId,
		isSendQyh:isSendQyh,
		isSendOo:isSendOo,
		isSendOt:isSendOt,
		sendStatus:sendStatus,
		planEndDate:planEndDate
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};